package info.motteke.kurumi.swt;

import info.motteke.kurumi.VoiceBlock;
import info.motteke.kurumi.VoiceRelation;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;

public class SwtVoiceRelation implements VoiceRelation {

    @SuppressWarnings("unused")
    private static final Log log = LogFactory.getLog(SwtVoiceRelation.class);

    private final Composite parent;

    private ScrolledComposite sc;

    private Composite base;

    private final List<VoiceBlock> blocks = new ArrayList<VoiceBlock>();

    public SwtVoiceRelation(Composite parent) {
        this.parent = parent;
        create();
    }

    private void create() {
        sc = new ScrolledComposite(parent, SWT.V_SCROLL);
        sc.setLayout(new FillLayout());
        base = new Composite(sc, SWT.BORDER);
        base.setLayout(new GridLayout(1, true));
        base.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_GREEN));

        sc.setContent(base);
    }

    @Override
    public void addVoiceBlock(VoiceBlock block) {
        blocks.add(block);
    }

    @Override
    public void clear() {
        for(VoiceBlock block : blocks){
            block.close();
        }
    }

    public Composite getBase() {
        return base;
    }

    @Override
    public void reflesh() {
        sc.layout();
//        base.layout();
    }
}
